<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app">
        <cpn :number1='num1' :number2='num2'
            @num1change='num1change' @num2change='num2change'></cpn>
    </div>

    <template id="cpn">
        <div>
            <h2>props:{{number1}}</h2>
            <h2>data:{{dnumber1}}</h2>
            <input type="text" placeholder="请输入值1" v-model='dnumber1'>
            <h2>props:{{number2}}</h2>
            <h2>data:{{dnumber2}}</h2>
            <input type="text" placeholder="请输入值2" v-model='dnumber2'>
        </div>
    </template>
    <script src= '../js/vue.js'></script>
    <script>
        const cpn = {
            template: '#cpn',
            props:{
                number1:{
                    type:Number
                },
                number2:{
                    type:Number
                }
            },
            data() {
                return {
                    dnumber1:this.number1,
                    dnumber2:this.number2
                }
            },
            watch: {
                dnumber1(newValue, oldValue) {
                    this.dnumber2 = newValue * 100;
                    this.$emit('num1change', newValue);
                },
                dnumber2(newValue, oldValue) {
                    this.dnumber1 = newValue / 100;
                    this.$emit('num2change', newValue);
                }
            }
        }
        const app = new Vue({
            el:'#app',
            data:{
                num1:1,
                num2:0
            },
            components:{
                cpn
            },
            methods:{
                num1change(value) {
                    this.num1 = parseFloat(value);
                },
                num2change(value) {
                    this.num2 = parseFloat(value);
                }
            }
        })
    </script>
</body>
</html>